#include "game_state.h"
#include "metrics.h"
#include "resman/file_tracker.h"

#include "game_flow_manager.h"
#include "audio/audio.h"


#include "util/timer.h"		    // Needs to come in early
#include "util/log.h"				// log
#include "util/common_macros.h"		// macros
#include "util/mmgr.h"		    

#include <cassert>

using namespace gameflow;


GameState::GameState() :
	m_Name("Base State"),
	m_OnEnter(0),
	m_IsCurrent(false),
	m_FrameC(0)
{
}

GameState::~GameState()
{
}

bool GameState::OnEnter()
{
	_LOG(MSG_COMMENT, "Entering game state " << m_Name);

	m_OnEnter = TIMER().GetTimeStamp();
	ACCUMULATE_METRIC(m_Name+"_state_fps", TIMER().FPS());

	m_IsCurrent = true;
	return true;
}

bool GameState::OnExit()
{
	_LOG(MSG_COMMENT, "Exiting game state " << m_Name);

	// update the timestamp

	float	Stamp = TIMER().GetTimeStamp();
	ACCUMULATE_METRIC(m_Name+"_state",  Stamp - m_OnEnter);

	// audio for screen shift
	AUDIO().PlayEvent("screen_transition");

	m_IsCurrent = false;
	return true;
}

void	GameState::GoPrevMenu()
{
	if (!m_PrevMenu.empty())
		gameflow::GameFlowManager::Instance().SetTransitionEffect("", m_PrevMenu, "");
}

bool	GameState::Tick(float dt)
{
	m_FrameC++;
	// update input
	return true;
}